import request from '@/utils/request';
import IS_MOCK, { BASE_URL } from '@/utils/url';

export async function getUserList(params) {
  const { pagination, formData } = params;
  return IS_MOCK
    ? request(`/api/user/getUserlist`, {
      method: 'post',
      data: {
        size: '10',
        start: '1',
        ...params.formData,
      },
    })
    : request(`${BASE_URL}/user/getUserlist?size=${pagination.size}&start=${pagination.start}`, {
      method: 'POST',
      data: {
        ...formData,
      },
    });
}

export async function addNewUser(params) {
  return IS_MOCK
    ? request('/api/user/insert', {
      method: 'post',
    })
    : request(`${BASE_URL}/user/insert`, {
      method: 'post',
      data: params,
    });
}

export async function updateUser(params) {
  return IS_MOCK
    ? request('/api/user/update', {
      method: 'post',
    })
    : request(`${BASE_URL}/user/insert`, {
      method: 'post',
      data: params,
    });
}
export async function deleteUser(params) {
  return IS_MOCK
    ? request('/api/user/delete', {
      method: 'post',
    })
    : request(`${BASE_URL}/user/delete?id=` + `${params.id}`, {
      method: 'get',
    });
}
